<html>
<body>


<form action="calculator.php" method="POST">
<input type="text" name="input" />
<input type="submit" />
</form>


<?php


if($_POST["input"])
{
	if ( preg_match( '/\d+|[+\-*\/]/', $_POST["input"], $matches ) )
	{
		$equ=$_POST["input"];
		eval("\$ans= $equ;");
		echo "ans= ".$ans;
	}
	else
		{
			echo "Invalid input.<br />";
		}
}


?>

</body>
</html>